package minishell;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.lex.io.IO;

import minishell.object.IObject;
import minishell.object.PairObject;

public class Environment
{
	
	private static Environment instance;
	static
	{
		instance = new Environment();
		instance.directory = new File( "." );
	}
	
	private boolean exit = false;
	private File directory = null;
	
	public static Environment getInstance()
	{
		return instance;
	}
	
	private Environment(){}
	
	public File getDirectory()
	{
		return directory;
	}
	public void setDirectory( File directory )
	{
		this.directory = IO.getCanonicalFile( directory );
	}
	
	public boolean isExit()
	{
		return exit;
	}

	public void setExit( boolean exit )
	{
		this.exit = exit;
	}

	public List<IObject> list()
	{
		List<IObject> list = new ArrayList<IObject>(2);
		list.add( new PairObject<String, String>( 
			"directory", IO.getCanonicalPath( getDirectory() ) ) );
		list.add( new PairObject<String, String>(
			"exit", Boolean.toString( exit ) ) );
		return list;
//		return Collections.iterator( "directory = " + IO.getCanonicalPath( 
//			getDirectory() ), "exit = " + exit );
	}
}
